<template>
  <el-button type="primary" size="small" icon="el-icon-plus" @click="doShow()">批量加分录</el-button>
  <el-dialog title="批量加行" v-model="show" center width="550px" top="70px"  :append-to-body="true" :close-on-press-escape="true" :close-on-click-modal="false">
    <div class="content">
      <div class="row">
        <span>行数</span><el-input-number size="small" v-model="row" :precision="0" style="width: 150px; margin: 0 10px" :min="0" />
      </div>
      <div class="rowCount">
        <span>重量</span><el-input-number size="small" v-model="rowCount" :precision="2" style="width: 150px; margin: 0 10px" :min="0" />
      </div>
    </div>
    <div class="footer">
      <el-button  type="primary" icon="el-icon-check" size="small" v-on:click="doSave()">确认</el-button>
      <el-button v-on:click="show = false" icon="el-icon-back" size="small" >关闭</el-button>
    </div>
  </el-dialog>
</template>

<script setup>
import clipboard from "vue-clipboard3";
import { getCurrentInstance, ref } from "vue";
import {getBoxNo} from "../../utils";

let show = ref(false)
let content = ref('')
let row = ref(0)
let rowCount = ref(0)

const { proxy } = getCurrentInstance()
const { toClipboard } = clipboard()
defineProps({
  boxNoType: { type: String, default: '' }
})


// 打开对话框
const doShow = val => {
  show.value = true
  content.value = val
  rowCount.value = 0
  row.value = 0
}

// 复制处理
const doSave = async() => {
  let boxList = []
  for (let i = 0; i < row.value; i++) {
    boxList.push({
      count: rowCount.value,
      boxNo: getBoxNo(proxy.boxNoType, i),
      inStock: false,
      perInBillNo: ''
    })
  }
  proxy.$emit('success', boxList)
  show.value = false
}
</script>

<style scoped lang="scss">
.content {
  padding: 30px 20px;
  display: flex;
  .row {
    padding-left: 10px;
  }
  .rowCount {
    padding-left: 40px;
  }
}
</style>
